package main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import mdp.State;
import mdp.ValueIteration;
import env.City;
import env.Road;
import env.World;

public class Main
{
	// constants
	public static final int			noOpCost	= 1,
			hellBreakLooseCost = 100000000, goalScore = 100;
	public static String			initialArmyCity	= "2",
			initialAgentCity = "1", initialChemCity = "1", goalCity = "4";
	public static ValueIteration	valueIteration;
	public static Double			delta			= 1.0;

	public static void main(String[] args)
	{
		World world = utils.Parser.parseWorldFile("world.txt");
		System.out.print(world.output() + "\n");
		valueIteration = new ValueIteration(world);
		valueIteration.init();
		valueIteration.calculate();
		//		valueIteration.printStates();
		//		valueIteration.simulate();

		boolean go = true;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while (go)
		{
			System.out
					.println("Choose action:\n\t1)print states\n\t2)simulate\n\t3)Quit");
			try
			{
				line = br.readLine();
				switch (line.charAt(0))
				{
				case '1':
					printer();
					break;
				case '2':
					valueIteration.simulate();
					break;
				case '3':
					go = false;
					break;
				}
			} catch (IOException e)
			{
				// TODO Auto-generated catch block
				System.out.print("exception");

			}
		}

	}

	public static void printer()
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		System.out
				.println("what to print:\n\t1)print all states\n\t2)print initial states\n\t3)print final states");
		try
		{
			line = br.readLine();

			switch (line.charAt(0))
			{
			case '1':
				Main.valueIteration.printStates();
				break;
			case '2':
				Main.valueIteration.printInitialStates();
				break;
			case '3':
				Main.valueIteration.printFinalStates();
				break;
			}
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			System.out.print("exception");
		}
	}
}
